package encore.portal.container;

import java.util.ArrayList;
import java.util.List;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import encore.log.Logger;
import encore.log.LoggerFactory;

public class Configuration {

	private static final Logger logger=LoggerFactory.getLogger(Configuration.class);
	
	/**
	 * 配置文件路径
	 */
	private static final ResourceBundle BUNDLE=ResourceBundle.getBundle("encore.portal.container.configuration");
	private static Boolean prevent;
	private static Boolean buffering;
	
	public static String getPortletAppDescriptorServiceImpl()
	{
		String impl=BUNDLE.getString("descriptors.services.PortletAppDescriptorService");
		if(logger.isDebugEnabled())
		{
			logger.debug(impl);
		}
		return impl;
	}
	
	
	public static boolean isBufferingSupported()
	{
		if(buffering==null)
		{
			try{
			  String buffer=BUNDLE.getString("ALLOW_BUFFER");
			  buffering=new Boolean(buffer);
			}catch (MissingResourceException e) {
			      buffering=Boolean.FALSE;
			}
			
		}
		return buffering.booleanValue();
	}
	
	
	public static List<String> getSupportedContainerRuntimeOptions()
	{
	  String options=BUNDLE.getString("supportedContainerRuntimeOptions");	
	  List<String> result=new ArrayList<String>();
	  String[] s=options.split(",");
	  for(String string:s)
	  {
		  result.add(string);
		  
	  }
	  return result;
	}
	
	
	  public static boolean preventUnecessaryCrossContext() {
		    if (prevent == null) {
		      try {
		        String test = BUNDLE.getString("PREVENT_UNECESSARY_CROSS_CONTEXT");
		        prevent = new Boolean(test);
		      } catch (MissingResourceException mre) {
		        prevent = Boolean.FALSE;
		      }
		    }
		    return prevent.booleanValue();
		  }
	  
	  public static final String getPortletContainerName()
	  {
	    return BUNDLE.getString("container.name");
	  }

	  public static final String getPortletContainerVersion()
	  {
	    return BUNDLE.getString("container.version");
	  }

	  public static final int getMajorSpecificationVersion()
	  {
	    return Integer.parseInt(BUNDLE.getString("javax.portlet.version.major"));
	  }

	  public static final int getMinorSpecificationVersion()
	  {
	    return Integer.parseInt(BUNDLE.getString("javax.portlet.version.minor"));
	  }

	  public static final String getServerInfo()
	  {
	    StringBuffer sb = new StringBuffer(getPortletContainerName()).append("/").append(getPortletContainerVersion());

	    return sb.toString();
	  }
}
